﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Xml;
using System.IO;
using log4net.Config;

namespace _180FrameWork.Common
{
    public class MyLogerHelper
    {
        static MyLogerHelper()
        {
            Init();
        }

        private static ILog _loginfo = null;

        public static ILog loginfo
        {
            get
            {
                if (_loginfo == null)
                    _loginfo = LogManager.GetLogger("loginfo");
                return _loginfo;
            }
        }

        private static ILog _logerror = null;

        public static ILog logerror
        {
            get
            {
                if (_logerror == null)
                    _logerror = LogManager.GetLogger("logerror");
                return _logerror;
            }
        }

        private static void Init()
        {
            FileInfo f = new FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + @"\" + "myloger.xml");
            if (f.Exists)
            {
                XmlConfigurator.Configure(f);
            }
        }

        public static void WriteLog(string info)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(info);
            }
        }

        public static void WriteLog(string info, Exception se)
        {
            if (logerror.IsErrorEnabled)
            {
                logerror.Error(info, se);
            }
        }
    }
}

